package code;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class RemoveDuplicateNodes_day04 {
    public static void main(String[] args) {

        ListNode head = new ListNode(0);head.next = null;
        ListNode node1 = new ListNode(1);node1.next = null;head.next=node1;
        ListNode node2 = new ListNode(2);node2.next = null;node1.next=node2;
        ListNode node3 = new ListNode(3);node3.next = null;node2.next=node3;
        ListNode node4 = new ListNode(4);node4.next = null;node3.next=node4;
        ListNode node5 = new ListNode(5);node5.next = null;node4.next=node5;
        ListNode node6 = new ListNode(6);node6.next = null;node5.next=node6;
        ListNode node7 = new ListNode(7);node7.next = null;node6.next=node7;
        ListNode node8 = new ListNode(8);node8.next = null;node7.next=node8;
        //
        ListNode p=head.next;
        if(p==null)return;
        //新链表
        ListNode newList=new ListNode(0);newList.next = null;
        ListNode q=newList;
        //存放数
        List<Integer> list = new ArrayList<>();
        list.add(p.val);
        p=p.next;

        while(p!=null){
            if(list.contains(p.val)){
                p=p.next;
            }else {
                list.add(p.val);
                ListNode temp=new ListNode(p.val);
                q.next=temp;
                q=temp;
                p=p.next;
            }
        }

    }
    public static class ListNode {
        int val;
        ListNode next;
        ListNode() {}
        ListNode(int val) { this.val = val; }
        ListNode(int val, ListNode next) { this.val = val; this.next = next; }
  }
}
